﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using Acms.Bll;

namespace Acms.AcmsControls.ContentControls.Admin
{
    public interface IBaseAdminEdit
    {
        void Save();
    }

    public abstract class BaseAdminEdit<T> : BaseAdminDisplay<T>, IBaseAdminEdit where T : BaseContentControlProperties, new()
    {
        public void Save()
        {
            PostControl control = GetControl();
            if (control != null)
            {
                T properties = LoadData(control.Value);
                if (properties == null)
                {
                    properties = new T();
                }
                SaveToProperties(properties, control);

                ForceSave(control, properties);
            }
        }

        protected abstract void SaveToProperties(T properties, PostControl control);
    }
}
